package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 衷岚
 * @version 1.0
 */

@RestController
@RequestMapping("/admin/category")
@Slf4j
public class CategoryController {


    @Autowired
    private CategoryService categoryService;

    @ApiOperation("新增菜品")
    @PostMapping
    public Result add(@RequestBody CategoryDTO categoryDTO) {
        log.info("新增菜品参数：{}",categoryDTO);
        categoryService.add(categoryDTO);
        return Result.success();
    }


    @ApiOperation("更新菜品分类信息")
    @PutMapping
    public Result update(@RequestBody CategoryDTO categoryDTO) {
        log.info("更新菜品参数：{}",categoryDTO);
        categoryService.update(categoryDTO);
        return Result.success();

    }

    @ApiOperation("删除菜品分类")
    @DeleteMapping
    public Result deleteById(Long id) {
        log.info("删除菜品id:{}",id);
        categoryService.deleteById(id);
        return Result.success();
    }

    @ApiOperation("更新启用禁用状态")
    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable("status") Integer status,Long id) {
        log.info("更新菜品状态：{}",status);
        categoryService.updateStatus(status,id);
        return Result.success();
    }

    @ApiOperation("根据类型查询菜品")
    @GetMapping("/list")
    public Result list(Integer type){
        log.info("菜品类型：{}",type);
        List<Category> categoryList = categoryService.list(type);
        return Result.success(categoryList);
    }

    @ApiOperation("菜品分类分页查询")
    @GetMapping("/page")
    public Result<PageResult> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO){
        log.info("菜品分页查询参数{}",categoryPageQueryDTO);
        PageResult pageResult = categoryService.pageQuery(categoryPageQueryDTO);
        return Result.success(pageResult);

    }










}
